package com.zjdiepu.www.manage.api.system;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.ibiz.system.IDpSuggestionBoxService;
import com.zjdiepu.www.model.system.dto.DpSuggestionBox;

/**      
* 项目名称：dpqc-parent-manager-home   
* 类名称：SuggestionBoxController   
* 类描述：   
* 创建人：zhangzj
* 创建时间：2017年4月12日 上午9:42:40   
* 修改人：zhangzj
* 修改时间：2017年4月12日 上午9:42:40   
* 修改备注：   
* @version V1.0     
*/ 
@Controller
@RequestMapping("/SuggestionBoxController")
public class SuggestionBoxController extends BaseController{

	@Resource
	private IDpSuggestionBoxService suggestionService=null;
	
	/** 
	* @author zhangzj
	* @Title: getSuggestionBoxtPages 
	* @Description: 获取列表分页信息
	* @param @param page
	* @param @param rows
	* @param @param suggestion
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/getSuggestionBoxtPages")
	public Map<String, Object> getSuggestionBoxtPages(Integer page,Integer rows,String suggestion){
		Map<String, Object> maps = super.success();
		try 
		{
			Map<String, Object> aWhere = CollectionInitUtil.emptyMap();
//			if(null != remitAccount && !("").equals(remitAccount))
//			{
//				aWhere.put("accountName", remitAccount);
//			}
			PageInfo<DpSuggestionBox> pageinfo = suggestionService.queryByPage(page,rows,aWhere);
			
			maps.put("rows", pageinfo.getList());
			maps.put("total", pageinfo.getLastPage());
			maps.put("records", pageinfo.getTotal()); //获取返回的记录数  
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || getSuggestionBoxtPages");
		}
		return maps;
	}
	/** 
	* @author zhangzj
	* @Title: insert 
	* @Description: 增加一条数据
	* @param @param box
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/insert")
	public Map<String,Object> insert(DpSuggestionBox box){
		Map<String, Object> maps = super.success();
		try 
		{
			box.setId(UUIDFactory.getUUID());
			suggestionService.insert(box);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || insert");
		}
		return maps;
	}
	/** 
	* @author zhangzj
	* @Title: getById 
	* @Description: 通过id查数据
	* @param @param id
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/getById")
	public Map<String,Object> getById(String id){
		Map<String, Object> maps = super.success();
		try 
		{	
			Map<String, Object> aWhere = CollectionInitUtil.emptyMap();
			if(null != id && !("").equals(id))
			{
				aWhere.put("id", id);
			}
			DpSuggestionBox dpSuggestionBox=suggestionService.getById(id);
			maps.put("result", dpSuggestionBox);
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || getById");
		}
		return maps;
	}
	/** 
	* @author zhangzj
	* @Title: update 
	* 
	* @param @param dpSuggestionBox
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/update")
	public Map<String,Object> update(DpSuggestionBox dpSuggestionBox){
		Map<String, Object> maps = super.success();
		try 
		{	
			suggestionService.update(dpSuggestionBox);
			System.out.println("-------------update");
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || udpate");
		}
		return maps;
	}
	/** 
	* @author zhangzj
	* @Title: delete 
	* 
	* @param @param id
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ResponseBody
	@RequestMapping("/delete")
	public Map<String,Object> delete(String id){
		Map<String, Object> maps = super.success();
		try 
		{	
			suggestionService.delete(id);
			System.out.println("-------------delete success!");
		}
		catch (Exception e) 
		{
			return super.errorMassage(e, "出错了  Exception  || delete");
		}
		return maps;
	}
}
